using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SettingPanel : BasePanel<SettingPanel>
{
    public CustomGUISlider sliderMusic;
    public CustomGUISlider sliderSound;

    public CustomGUIToggle toggleMusic;
    public CustomGUIToggle toggleSound;

    public CustomGUIButton btnClose;

    // Start is called before the first frame update
    void Start()
    {
        sliderMusic.changeValue += (value) =>
        {
            MusicManager.Instance.ChangeVolume(value);
            GameDataManager.Instance.ChangeMusicValue(value);
        };

        sliderSound.changeValue += (value) => GameDataManager.Instance.ChangeSoundValue(value);

        toggleMusic.changeValue += (value) =>
        {
            MusicManager.Instance.OpenOrCloseMusic(value);
            GameDataManager.Instance.OpenOrCloseMusic(value);
        };

        toggleSound.changeValue += (value) => GameDataManager.Instance.OpenOrCloseSound(value);

        btnClose.clickEvent += () =>
        {
            HiddenMe();
            if (SceneManager.GetActiveScene().name.Equals("BeginScene"))
            {
                BeginPanel.Instance.ShowMe();
            }
        };
        HiddenMe();
    }


    private void UpdateInfo()
    {
        MusicData musicData = GameDataManager.Instance.musicData;
        sliderMusic.nowValue = musicData.musicValue;
        sliderSound.nowValue = musicData.soundValue;
        toggleMusic.isSel = musicData.isOpenMusic;
        toggleSound.isSel = musicData.isOpenSound;
    }

    public override void ShowMe()
    {
        base.ShowMe();
        UpdateInfo();
    }
        public override void HiddenMe()
        {
            base.HiddenMe();
            Time.timeScale = 1;
        }
}